<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="城市id" prop="cityId">
        <el-input
          v-model="queryParams.cityId"
          placeholder="请输入城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出行人手机号" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入出行人手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="酒店名" prop="hotelName">
        <el-input
          v-model="queryParams.hotelName"
          placeholder="请输入酒店名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="酒店位置" prop="hotelAddress">
        <el-input
          v-model="queryParams.hotelAddress"
          placeholder="请输入酒店位置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入住时间" prop="checkInTime">
        <el-date-picker clearable
          v-model="queryParams.checkInTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择入住时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="退房时间" prop="checkOutTime">
        <el-input
          v-model="queryParams.checkOutTime"
          placeholder="请输入退房时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房间数量" prop="roomCount">
        <el-input
          v-model="queryParams.roomCount"
          placeholder="请输入房间数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="住客名" prop="guestName">
        <el-input
          v-model="queryParams.guestName"
          placeholder="请输入住客名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮件" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预计到店时间" prop="expectTime">
        <el-date-picker clearable
          v-model="queryParams.expectTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择预计到店时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="特别要求" prop="specialRequirement">
        <el-input
          v-model="queryParams.specialRequirement"
          placeholder="请输入特别要求"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="租车套餐id" prop="carPackageId">
        <el-input
          v-model="queryParams.carPackageId"
          placeholder="请输入租车套餐"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="租车起始时间" prop="carStartTime">
        <el-date-picker clearable
          v-model="queryParams.carStartTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择租车起始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="租车结束时间" prop="carStopTime">
        <el-date-picker clearable
          v-model="queryParams.carStopTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择租车结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="驾驶人" prop="driverName">
        <el-input
          v-model="queryParams.driverName"
          placeholder="请输入驾驶人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总价" prop="totalPrice">
        <el-input
          v-model="queryParams.totalPrice"
          placeholder="请输入总价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:order:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单id" align="center" prop="id" />
      <el-table-column label="订单类型(1、酒店  2、机票  3、火车票  4、租车)" align="center" prop="orderType" />
      <el-table-column label="城市" align="center" prop="cityId" />
      <el-table-column label="身份证号" align="center" prop="idNumber" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="出行人手机号" align="center" prop="phoneNumber" />
      <el-table-column label="酒店名" align="center" prop="hotelName" />
      <el-table-column label="酒店位置" align="center" prop="hotelAddress" />
      <el-table-column label="房间id" align="center" prop="hotelRoomType" />
      <el-table-column label="入住时间" align="center" prop="checkInTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkInTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="退房时间" align="center" prop="checkOutTime" />
      <el-table-column label="房间数量" align="center" prop="roomCount" />
      <el-table-column label="住客名" align="center" prop="guestName" />
      <el-table-column label="邮件" align="center" prop="email" />
      <el-table-column label="预计到店时间" align="center" prop="expectTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expectTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="特别要求" align="center" prop="specialRequirement" />
      <el-table-column label="租车套餐" align="center" prop="carPackageId" />
      <el-table-column label="租车起始时间" align="center" prop="carStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.carStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="租车结束时间" align="center" prop="carStopTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.carStopTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="驾驶人" align="center" prop="driverName" />
      <el-table-column label="订单状态(1、未付款  2、已付款  3、已取消  4、已完成)" align="center" prop="status" />
      <el-table-column label="总价" align="center" prop="totalPrice" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:order:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="城市" prop="cityId">
          <el-input v-model="form.cityId" placeholder="请输入城市" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="出行人手机号" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入出行人手机号" />
        </el-form-item>
        <el-form-item label="酒店名" prop="hotelName">
          <el-input v-model="form.hotelName" placeholder="请输入酒店名" />
        </el-form-item>
        <el-form-item label="酒店位置" prop="hotelAddress">
          <el-input v-model="form.hotelAddress" placeholder="请输入酒店位置" />
        </el-form-item>
        <el-form-item label="入住时间" prop="checkInTime">
          <el-date-picker clearable
            v-model="form.checkInTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入住时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="退房时间" prop="checkOutTime">
          <el-input v-model="form.checkOutTime" placeholder="请输入退房时间" />
        </el-form-item>
        <el-form-item label="房间数量" prop="roomCount">
          <el-input v-model="form.roomCount" placeholder="请输入房间数量" />
        </el-form-item>
        <el-form-item label="住客名" prop="guestName">
          <el-input v-model="form.guestName" placeholder="请输入住客名" />
        </el-form-item>
        <el-form-item label="邮件" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮件" />
        </el-form-item>
        <el-form-item label="预计到店时间" prop="expectTime">
          <el-date-picker clearable
            v-model="form.expectTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预计到店时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="特别要求" prop="specialRequirement">
          <el-input v-model="form.specialRequirement" placeholder="请输入特别要求" />
        </el-form-item>
        <el-form-item label="租车套餐" prop="carPackageId">
          <el-input v-model="form.carPackageId" placeholder="请输入租车套餐" />
        </el-form-item>
        <el-form-item label="租车起始时间" prop="carStartTime">
          <el-date-picker clearable
            v-model="form.carStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择租车起始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="租车结束时间" prop="carStopTime">
          <el-date-picker clearable
            v-model="form.carStopTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择租车结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="驾驶人" prop="driverName">
          <el-input v-model="form.driverName" placeholder="请输入驾驶人" />
        </el-form-item>
        <el-form-item label="总价" prop="totalPrice">
          <el-input v-model="form.totalPrice" placeholder="请输入总价" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/system/ctrip/order";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单管理表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderType: null,
        cityId: null,
        idNumber: null,
        name: null,
        phoneNumber: null,
        hotelName: null,
        hotelAddress: null,
        hotelRoomType: null,
        checkInTime: null,
        checkOutTime: null,
        roomCount: null,
        guestName: null,
        email: null,
        expectTime: null,
        specialRequirement: null,
        carPackageId: null,
        carStartTime: null,
        carStopTime: null,
        driverName: null,
        status: null,
        totalPrice: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderType: [
          { required: true, message: "订单类型(1、酒店  2、机票  3、火车票  4、租车)不能为空", trigger: "change" }
        ],
        cityId: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "订单状态(1、未付款  2、已付款  3、已取消  4、已完成)不能为空", trigger: "change" }
        ],
        totalPrice: [
          { required: true, message: "总价不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单管理列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderType: null,
        cityId: null,
        idNumber: null,
        name: null,
        phoneNumber: null,
        hotelName: null,
        hotelAddress: null,
        hotelRoomType: null,
        checkInTime: null,
        checkOutTime: null,
        roomCount: null,
        guestName: null,
        email: null,
        expectTime: null,
        specialRequirement: null,
        carPackageId: null,
        carStartTime: null,
        carStopTime: null,
        driverName: null,
        status: null,
        totalPrice: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单管理编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
